package api;

import model.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.*;

@WebServlet("/api/delete.json")
public class Delete extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String jid = req.getParameter("jid");
          delete(jid);
        resp.sendRedirect("/MyPost.html");
    }
      public static void delete(String jid){
          try {
              try(Connection c = DBUtil.getConnection()){
                  String sql = "DELETE from job WHERE jid = ?";
                  try (PreparedStatement s = c.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
                      s.setString(1,jid);
                      s.executeUpdate();
                  }
              }
          } catch (SQLException exception) {
              exception.printStackTrace();
          }
      }
}
